var app = getApp(); 
Page({
  data: {
    remark:true,
    disble:false,
    btnname: "确认提交",
    AreaName:'',
    AreaId:'',
    items: [],
    Temp: true,
    date: '2020-01-01',
    fdate: '2020-06-13',
    scrollTop:0,
  },
  onLoad: function () {    
    this.getitem();  
  },
  
onPageScroll: function (e) {
 
  this.setData({
  scrollTop:e.scrollTop
  })
},
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value
    })

  },
  bindfDateChange: function (e) {
    this.setData({
      fdate: e.detail.value
    })
  },
  getDate: function () {
    var that = this;
   
    wx.cloud.callFunction({
      name: 'GetPost',
      data: {
        data: "fun=3&QueryStr=" + that.data.date + "&QueryStr1=" + that.data.fdate + "&QueryStr2="+app.globalData.name+"&QueryStr3="+that.data.AreaId
        // data: "fun=3&QueryStr=2020-01-01&QueryStr1=2020-06-13&QueryStr2=彭刚&QueryStr3="+that.data.AreaId         
      },
      success: res => {
        console.log(res);
        let obj = JSON.parse(res.result)
        that.setData({ list: obj })
      },
      fail: err => {
        wx.showToast({
          icon: 'none',
          title: '调用失败',
        })
      }
    })
  },
  wselect(e){    
    var that=this;
    var Index=e.detail.value;
    console.log(Index);
     this.setData({
       AreaName:that.data.items[Index].FullName,
       AreaId:that.data.items[Index].typeId
     })    
  },
  getitem: function () {
    console.log(app.globalData.name);
    var that = this;    
    wx.cloud.callFunction({
      name: 'GetPost',
      data: {
       data: "fun=2&QueryStr="+app.globalData.name
        // data: "fun=2&QueryStr=彭刚"
      },
      success: res => {
        console.log("===>"+res.result);
        let obj = JSON.parse(res.result)
        that.setData({ items: obj })  
        
        if (that.data.items.length==0){
          that.setData({disble:true})
        }
      },
      fail: err => {
        console.error('[云函数] [login] 调用失败', err);
        wx.showToast({
          icon: 'none',
          title: '调用失败',
        })
      }
    })

  },
  submitForm: function () {
    var fdate = this.data.fdate;
    var date = this.data.date;

    if (fdate.substring(1, 4) != date.substring(1, 4)) {
      wx.showModal({
        title: '提示',
        content: '不支持跨年查询~',
        showCancel: false
      })
      return false;
    };
    this.setData({ Temp: false,remark:false });
    this.getDate();
  },
  showit:function(){
  this.setData({remark:true });
}
})